<template>
    <div style="overflow:hidden;-webkit-app-region: drag">
        <div class="bodyBox">
            <div class="boxTop">
                找回密码
                <div class="imgBox">
                    <img src="../../assets/img/login/images/findpasas_03.png" alt="" @click="close" style="-webkit-app-region: no-drag;">
                </div>
            </div>
            <div class="stepone">
                <div class="onebigStep twobigStep">
                    <div class="onesmall twosmall">
                        1
                    </div>    
                </div>
                <div class="line"></div>
                <div class="onebigStep ">
                    <div class="onesmall ">
                        2
                    </div>    
                </div>
            </div>
            <div class="userinput">
                新密码    
                <input type="password" v-model="newpass" placeholder="请输入您的新密码" class="username" v-on:blur="password" style="margin-left: 23px;-webkit-app-region: no-drag;">
                <div class="error signbox" :class="{errordata:signsuccess}">
                    <img src="../../assets/img/login/images/error_03.png" alt="">
                    <span class="spanone">新密码必须为6-16位数字和字母的组合</span>
                </div>
            </div>
            <div class="userinput newinput">
                确认密码
                <input type="password" v-model="newpassdata" placeholder="请确认您的新密码" class="username" style="-webkit-app-region: no-drag;">
                <div class="error signbox" :class="{errordata:passshow}">
                    <img src="../../assets/img/login/images/error_03.png" alt="">
                    <span class="spanone">新密码和确认密码不一致，请重新输入</span>
                </div>
            </div>
            <div class="nextstep" @click="finished" style="-webkit-app-region: no-drag;">
                完成
            </div>
        </div>
    </div>
</template>
<script>
if (window.require) {
  var ipc = window.require('electron').ipcRenderer
}
export default {
    name:"FindPasstwo",
    data(){
        return{
            newpass:"",
            newpassdata:"",
            signsuccess:true,
            passshow:true,
        }
    },
    watch:{
        newpass:function(){
            this.signsuccess=true;
        },
        newpassdata:function(){
            this.passshow=true;
        }
    },
    methods:{
        password(){
            var pass=this.newpass;
            var passlen=pass.length;
            if(passlen<6||passlen>16){
                this.signsuccess=false;
            }else{
                var pPass1 = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/;
                var passres = pPass1.test(pass);
                if(passres==false){
                    this.signsuccess=false;
                }else{
                    this.signsuccess=true;
                }
            }
        },
        finished:function(){
            var pass=this.newpassdata;
            var passlen=pass.length;
            if(passlen<6||passlen>16){
                this.passshow=false;
            }else{
                var pPass1 = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/;
                var passres = pPass1.test(pass);
                if(passres==false){
                    this.passshow=false;
                }else{
                    if(this.newpass!=pass){
                        this.passshow=false;
                    }else{
                        this.passshow=true;
                        var uid = sessionStorage.uid;
                        this.https("common/postSetNewPassword",{uid:uid,new_password:this.newpass,new_repeat_password:this.newpassdata},'post').then(data=>{
                                this.$toast({
                                    message: '您已成功更改密码，请使用新密码登录',
                                    onClose:function(){
                                        ipc.send('pwdwindow-close');
                                    }
                                })
                        })
                       
                    }
                }
            }
        },
        close:function(){  //关闭注册页
            ipc.send('pwdwindow-close');
        }
    }
}
</script>
<style lang="less" scoped>
    @import url(../../assets/css/login/public.less);
    @import url(../../assets/css/login/findpasstwo.less);
</style>


